package admin.servlet;

import admin.entity.Dome;
import admin.service.UploadFile;
import admin.service.UploadFileImpl;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.net.httpserver.Authenticator;
import common.utils.HibernateUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import javax.xml.ws.Action;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.List;

import static com.sun.net.httpserver.Authenticator.*;

public class Servlet extends ActionSupport {
    private File[] domeUp;
    private String[] domeUpFileName;
    private String result;
    private String name;
    private String initialUrl;
    public String addDome(){
        System.out.println("提交");
        String domeUrl =null;
        String imgUrl = null;
        UploadFile uploadFile = new UploadFileImpl();
        int i = 0;
        for(File file : domeUp){
            for(String string : domeUpFileName){
                if(i==0){
            domeUrl = uploadFile.UploadDomeFile(file,string,initialUrl);i++;}else{
            imgUrl = uploadFile.UploadImgFile(file);}}}
        uploadFile.addDome(domeUrl,imgUrl,name);
        return "wrong";
    }
    public String execute(){
        return "wrong";
    }

    public String ajaxJson(){
        UploadFile uploadFile = new UploadFileImpl();
        List<Dome> list = uploadFile.selcetDome(0);
        JSONArray array = new JSONArray();
        for(Dome dome : list){
            JSONObject object = new JSONObject();
            object.put("domeUrl",dome.getDomeUrl());
            object.put("imgUrl",dome.getIndexImg());
            object.put("name",dome.getName());
            array.add(object);
        }
        result = array.toString();
        return SUCCESS;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getResult() {
        return result;
    }

    public File[] getDomeUp() {
        return domeUp;
    }

    public void setDomeUp(File[] domeUp) {
        this.domeUp = domeUp;
    }

    public String[] getDomeUpFileName() {
        return domeUpFileName;
    }

    public void setDomeUpFileName(String[] domeUpFileName) {
        this.domeUpFileName = domeUpFileName;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getInitialUrl() {
        return initialUrl;
    }

    public void setInitialUrl(String initialUrl) {
        this.initialUrl = initialUrl;
    }
}
